package com.example.xunua_zhinengjiaotong.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.xunua_zhinengjiaotong.R;
import com.example.xunua_zhinengjiaotong.utils.CarLogBean;

import java.util.ArrayList;

public class TrolleyMessageAdapter extends BaseAdapter {
    private ArrayList<CarLogBean> mData;
    private Context context;

    public TrolleyMessageAdapter(ArrayList<CarLogBean> mData, Context context) {
        this.mData = mData;
        this.context = context;
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int position) {
        return mData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder=null;
        if (convertView == null) {
            convertView= LayoutInflater.from(context).inflate(R.layout.item_lv_carlog,null);
            holder=new ViewHolder();
            holder.tv_id=convertView.findViewById(R.id.lv_Carlog_CarId_tv);
            holder.tv_money=convertView.findViewById(R.id.lv_Carlog_money_tv);
            holder.tv_time=convertView.findViewById(R.id.lv_Carlog_time_tv);
            holder.tv_addr=convertView.findViewById(R.id.lv_Carlog_addr_tv);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        holder.tv_id.setText(mData.get(position).getCarId());
        holder.tv_money.setText(mData.get(position).getCost());
        holder.tv_time.setText(mData.get(position).getTime());
        holder.tv_addr.setText(mData.get(position).getAddr());
        return convertView;
    }
    private class ViewHolder{
        private TextView tv_id,tv_money,tv_time,tv_addr;
    }
}
